package br.com.pixt;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.app.ActivityGroup;

public class TabCadastro extends ActivityGroup {

	public static TabCadastro group;	
	private ArrayList<View> history;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
    	super.onCreate(savedInstanceState);
    	
    	this.history = new ArrayList<View>();
    	group = this;
          
        Bundle params ;
  		Intent itParam = getIntent();
  		
  		Intent itListaHoras = new Intent().setClass(this, ListaHoras.class);
  		
  		if (itParam!=null)
  		{
  			params = itParam.getExtras();
  			itListaHoras.putExtras(params);
  		}

  		View view = getLocalActivityManager()
                                    .startActivity("ListaHoras", itListaHoras
                                    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                                    .getDecorView();
           this.replaceView(view);

       }
    
    public void replaceView(View v) 
    {
        // Adds the old one to history
    	history.add(v);
        // Changes this Groups View to the new View.
    	setContentView(v);
    }

    public void back() 
    {
    	if(history.size() > 0) 
    	{
    		history.remove(history.size()-1);
    		setContentView(history.get(history.size()-1));
    	}
    	else 
    	{
    		finish();
    	}
    }

    @Override
    public void onBackPressed() 
    {
    	TabCadastro.group.back();
    	return;
    }
}

